#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
const ll mod = 998244353;

struct Edge {
    int to, next;
} e[N << 1];

int head[N], idx = 1, a[N], n;

void add_edge(int u, int v) {
    e[idx].to = v;
    e[idx].next = head[u];
    head[u] = idx++;
}
void clear_graph() {
    memset(head, -1, sizeof(head));
    memset(e, 0, sizeof(e));
    idx = 1;
}

int far = -1; // 最远距离所在的点
ll res = -1; // 最远距离
int A, B, C;

int fa[N];

void dfs(int u, int f = -1, int d = 0) {
    if (d > res) res = d, far = u;
    for (int i = head[u]; ~i; i = e[i].next) {
        int j = e[i].to;
        if (j != f) {
            fa[j] = u;
            dfs(j, u, d + 1);
        }
    }
}

ll M[N];

void dfs2(int u, int f, int ss, int d = 0) {
    if (res % 2 && d == (res - 1) / 2) {
        M[ss]++;
    }

    if (res % 2 == 0 && d == res / 2 - 1) {
        M[ss]++;
    }

    for (int i = head[u]; ~i; i = e[i].next) {
        int j = e[i].to;
        if (j != f) {
            dfs2(j, u, ss, d + 1);
        }
    }
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    int u, v;
    clear_graph();

    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        add_edge(u, v), add_edge(v, u);
    }

    memset(fa, 0, sizeof(fa));
    dfs(1);
    res = -1; // 必须加上这句话，否则1点在直径端点会wa
    memset(fa, 0, sizeof(fa));
    dfs(far);

    vector<int> path;
    int cur = far;

    while (cur) {
        path.push_back(cur);
        cur = fa[cur];
    }
    memset(M, 0, sizeof(M));
    if (res % 2) {
        A = path[(res - 1) / 2], B = path[(res + 1) / 2];
        dfs2(A, B, 1), dfs2(B, A, 2);

        cout << M[1] * M[2] % mod << endl;
    }
    else {
        C = path[res / 2];
        vector<int> veck;
        for (int i = head[C]; ~i; i = e[i].next) {
            int T = e[i].to;
            veck.push_back(T);
        }

        int K = veck.size();
        for (int i = 0; i < K; i++)
            dfs2(veck[i], C, i);

        ll res = 1, x;

        for (int i = 0; i < K; i++) {
            x = M[i] + 1;
            res = (res * x) % mod;
        }

        for (int i = 0; i < K; i++) {
            x = M[i];
            res = (res + mod - x) % mod;
        }

        res = (res + mod - 1) % mod;
        cout << res << endl;
    }
    return 0;
}
